<template>
  <div>
    <div>
      <el-row :gutter="20">
        <el-form
          :model="policyForm"
          :rules="policyRules"
          ref="policyForm"
          label-width="90px"
        >
          <el-col :span="6">
            <el-form-item label="选择通道:" prop="aisleCode">
              <el-select
                size="small"
                v-model="policyForm.aisleCode"
                @change="aisleChange"
                placeholder="请选择通道"
              >
                <el-option
                  v-for="item in aisleList"
                  :key="item.aisleCode"
                  :label="item.aisleName"
                  :value="item.aisleCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策分类:" prop="polTypeCode">
              <el-select
                size="small"
                v-model="policyForm.polTypeCode"
                placeholder="请选择政策分类"
              >
                <el-option
                  :label="item.polTypeName"
                  :value="item.polTypeCode"
                  v-for="item in polTypeClassifyList"
                  :key="item.polTypeCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策名称:" prop="polName">
              <el-input
                size="small"
                v-model="policyForm.polName"
                placeholder="请输入政策名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="分润类型:" prop="profitType">
              <el-select
                size="small"
                v-model="policyForm.profitType"
                placeholder="请选择分润类型"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polTypeList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策种类:" prop="polKind">
              <el-select
                size="small"
                v-model="policyForm.polKind"
                placeholder="请选择政策种类"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polKindList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
    <div class="haruyuki-scrollbar-60vh haruyuki-p-10">
      <div class="aisle-policy-box" v-if="JSON.stringify(data) !== '{}'">
        <div
          class="
            haruyuki-width-100
            haruyuki-flex-space-between
            haruyuki-align-items-center
            aisle-policy-bg
          "
        >
          <div>
            <span
              class="haruyuki-size-16 policy-ml-3 policy-mr-3"
              @click.stop="data.isShow = !data.isShow"
              ><i
                :class="
                  data.isShow ? 'el-icon-caret-bottom' : 'el-icon-caret-right'
                "
              ></i
              >通道名称：{{ data.aisleName }}</span
            >
          </div>
          <div class="haruyuki-flex-center">
            <div class="haruyuki-mr-20">
              <span>成本费率：</span>
              <el-input-number
                size="mini"
                v-model="data.aptRate"
                :precision="4"
                :step="0.0001"
                :min="0"
                :max="1"
              ></el-input-number>
              <span> %</span>
            </div>
            <div class="haruyuki-mr-20">
              <span>结算比例：</span>
              <el-input-number
                size="mini"
                v-model="data.aptScale"
                :precision="0"
                :min="1"
                :max="100"
              ></el-input-number>
              <span> %</span>
            </div>
            <div class="haruyuki-mr-20">
              <span>最低金额：</span>
              <el-input-number
                size="mini"
                v-model="data.aptMin"
                :precision="2"
                :step="0.1"
                :min="0"
              ></el-input-number>
              <span> ¥</span>
            </div>
          </div>
          <div class="policy-mr-3">
            <el-button
              type="primary"
              size="mini"
              plain
              @click.stop="submitChildCover(data)"
              >一键填入</el-button
            >
          </div>
        </div>
        <div
          class="custom-tree-container"
          v-show="data.isShow"
          v-for="(interItem, interIndex) in data.intervalList"
          :key="interItem.id"
        >
          <div
            class="
              haruyuki-line-height-special
              haruyuki-flex
              haruyuki-align-items-center
              haruyuki-plr-20
            "
          >
            <div @click.stop="interItem.isShow = !interItem.isShow">
              <i
                :class="
                  interItem.isShow
                    ? 'el-icon-caret-bottom'
                    : 'el-icon-caret-right'
                "
              ></i
              >阶梯{{ interIndex + 1 }}：
            </div>
            <div class="haruyuki-flex haruyuki-align-items-center">
              范围区间：<el-input-number
                size="mini"
                v-model="interItem.aptStartMoney"
                :precision="2"
                :step="0.1"
                :min="0"
              ></el-input-number
              ><span>~</span
              ><el-input-number
                size="mini"
                v-model="interItem.aptEndMoney"
                :precision="2"
                :step="0.1"
                :min="0.1"
              ></el-input-number>
              <div
                class="policy-ml-3 policy-mr-3"
                v-if="interItem.id == stateIndex"
              >
                <el-button
                  type="text"
                  size="mini"
                  @click="() => ladderAppend(interItem)"
                >
                  新增
                </el-button>
              </div>
              <div
                class="policy-ml-3"
                v-if="interItem.id == stateIndex && interIndex != 0"
              >
                <el-button
                  type="text"
                  size="mini"
                  @click="() => ladderRemove(interIndex)"
                >
                  删除
                </el-button>
              </div>
            </div>
          </div>
          <div v-show="interItem.isShow">
            <div class="haruyuki-line-height-special haruyuki-plr-40">
              <span>扫码垫资费费率：</span>
              <el-input-number
                size="mini"
                v-model="interItem.codeAdvanceRate"
                :precision="4"
                :step="0.0001"
                :min="0"
                :max="1"
              ></el-input-number>
              <span> %</span>
            </div>
            <div class="haruyuki-line-height-special haruyuki-plr-40">
              <span>扫码垫资费费率最低值：</span>
              <el-input-number
                size="mini"
                v-model="interItem.codeAdvanceMin"
                :precision="2"
                :min="0"
                :max="9999999"
              ></el-input-number>
              <span> ¥</span>
            </div>
            <!-- START 扫码 -->
            <div
              class=""
              v-for="productItem in interItem.productList"
              :key="productItem.id"
            >
              <div
                class="haruyuki-line-height-special haruyuki-plr-40"
                @click.stop="productItem.isShow = !productItem.isShow"
              >
                <i
                  :class="
                    productItem.isShow
                      ? 'el-icon-caret-bottom'
                      : 'el-icon-caret-right'
                  "
                ></i>
                <span>{{ productItem.compName }}：</span>
              </div>
              <div v-if="productItem.isSingleInterval == 0">
                <div
                  v-show="productItem.isShow"
                  v-for="(
                    singleItem, singleIndex
                  ) in productItem.singlePayInterval"
                  :key="singleIndex"
                >
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="singleItem.aptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="singleItem.aptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="singleItem.aptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                </div>
              </div>

              <div v-if="productItem.isSingleInterval == 1">
                <div v-show="productItem.isShow">
                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>交易金额小于 </span>
                    <el-input-number
                      size="mini"
                      :disabled="true"
                      v-model="productItem.intervalMoney"
                      :precision="2"
                      :min="0"
                    ></el-input-number>
                    <span> 时</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                      :max="9999"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡封顶金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].aptMax"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>

                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].creditAptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].creditAptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[0].creditAptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>

                  <div class="haruyuki-line-height-special haruyuki-plr-60">
                    <span>交易金额大于 </span>
                    <el-input-number
                      size="mini"
                      :disabled="true"
                      v-model="productItem.intervalMoney"
                      :precision="2"
                      :min="0"
                    ></el-input-number>
                    <span> 时</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>借记卡封顶金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].aptMax"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>

                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡成本费率：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].creditAptRate"
                      :precision="4"
                      :step="0.0001"
                      :min="0"
                      :max="1"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡结算比例：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].creditAptScale"
                      :precision="0"
                      :min="1"
                      :max="100"
                    ></el-input-number>
                    <span> %</span>
                  </div>
                  <div class="haruyuki-line-height-special haruyuki-plr-80">
                    <span>贷记卡最低金额：</span>
                    <el-input-number
                      size="mini"
                      v-model="productItem.singlePayInterval[1].creditAptMin"
                      :precision="2"
                      :step="0.1"
                      :min="0"
                    ></el-input-number>
                    <span> ¥</span>
                  </div>
                </div>
              </div>
            </div>
            <!-- END 扫码 -->
            <!-- START 刷卡 -->
            <div
              class="haruyuki-line-height-special haruyuki-plr-40"
              @click.stop="interItem.posTrad.isShow = !interItem.posTrad.isShow"
            >
              <i
                :class="
                  interItem.posTrad.isShow
                    ? 'el-icon-caret-bottom'
                    : 'el-icon-caret-right'
                "
              ></i>
              <span>刷卡：</span>
            </div>
            <div
              v-show="interItem.posTrad.isShow"
            >
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡垫资费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditCodeAdvanceRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡垫资费率封顶：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditCodeAdvanceRateMax"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>贷记卡垫资费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.creditCodeAdvanceRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡费率封顶：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtRateMax"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡垫资费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtCodeAdvanceRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡垫资费率封顶：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtCodeAdvanceRateMax"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>借记卡垫资费率封底：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.debtCodeAdvanceRateMin"
                  :precision="2"
                  :step="0.1"
                  :min="0"
                ></el-input-number>
                <span> ¥</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>挥卡费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.waveRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60">
                <span>挥卡结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.waveScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>银联费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.unionpayRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>银联结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.unionpayScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>尊享费率：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.vipRate"
                  :precision="4"
                  :step="0.0001"
                  :min="0"
                  :max="1"
                ></el-input-number>
                <span> %</span>
              </div>
              <div class="haruyuki-line-height-special haruyuki-plr-60" v-if="interItem.posTrad.isShowVip == 1">
                <span>尊享结算比例：</span>
                <el-input-number
                  size="mini"
                  v-model="interItem.posTrad.vipScale"
                  :precision="0"
                  :min="1"
                  :max="100"
                ></el-input-number>
                <span> %</span>
              </div>
            </div>
            <!-- END 刷卡 -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getDictionary } from "@/api/system/dict";
import { getAisleList } from "@/api/rb-core/oempolicy/oem_policy";
import { detailFrame } from "@/api/rb-core/aislePolicy/aisle_policy";
import { getList } from "@/api/rb-core/policyType/policy_type";

let intId = 1;
let pid = 1000;
export default {
  props: {
    policyForm: Object,
  },
  data() {
    return {
      policyRules: {
        aisleCode: [
          { required: true, message: "请选择通道", trigger: "blur" },
        ],
        polTypeCode: [
          { required: true, message: "请选择政策分类", trigger: "blur" },
        ],
        polName: [
          { required: true, message: "请输入政策名称", trigger: "blur" },
        ],
        profitType: [
          { required: true, message: "请选择分润类型", trigger: "blur" },
        ],
        polKind: [
          { required: true, message: "请选择政策种类", trigger: "blur" },
        ],
      },
      aisleList: [], // 一键全入 模板集合
      polTypeList: [],
      polKindList: [],
      polTypeClassifyList: [],
      data: {}, //通道政策 树形数据
      stateIndex: null,
    };
  },
  watch: {
    "data.intervalList"(val) {
      if (val) {
        if (val.length >= 1) {
          this.stateIndex = val[val.length - 1].id;
        }
      }
    },
  },
  created() {
    this.data = {};
    this.doGetDicts();
    this.getAisleSelect();
  },
  methods: {
    /* 字典 */
    doGetDicts() {
      getDictionary({ code: "profit_type" }).then((res) => {
        this.polTypeList = res.data.data;
      });
      getDictionary({ code: "pol_kind" }).then((res) => {
        this.polKindList = res.data.data;
      });
    },
    /* 通道查询 */
    getAisleSelect() {
      getList("-1", "-1").then((res) => {
        this.polTypeClassifyList = res.data.data.records;
      });
      getAisleList("-1", "-1").then((res) => {
        this.aisleList = res.data.data.records;
      });
    },
    /* 编辑页面详情数据回显 */
    getEditDatail(data) {
      this.policyForm.aisleCode = data.aisleCode;
      this.policyForm.polName = data.polName;
      this.policyForm.polKind = data.polKind + "";
      this.policyForm.profitType = data.profitType + "";
      this.policyForm.polTypeCode = data.polTypeCode;

      let datas = data;
      this.$set(datas, "isShow", true);
      this.$set(datas, "aptMin", -1);
      this.$set(datas, "aptRate", -1);
      this.$set(datas, "aptScale", -1);

      for (let j = 0; j < datas.intervalList.length; j++) {
        this.$set(datas.intervalList[j], "isShow", true);
        this.$set(datas.intervalList[j], "id", intId++);
        this.$set(datas.intervalList[j].posTrad, "isShow", true);
        for (let k = 0; k < datas.intervalList[j].productList.length; k++) {
          this.$set(datas.intervalList[j].productList[k], "isShow", true);
          this.$set(datas.intervalList[j].productList[k], "id", pid++);
        }
      }
      this.$nextTick(() => {
        this.data = JSON.parse(JSON.stringify(datas));
      });
    },
    /* 通道选择 回显赋值政策 */
    aisleChange(e) {
      detailFrame(e).then((res) => {
        if (res.data.code == "200") {
          let datas = res.data.data;
          this.$set(datas, "isShow", true);
          this.$set(datas, "aptMin", -1);
          this.$set(datas, "aptRate", -1);
          this.$set(datas, "aptScale", -1);
          for (let j = 0; j < datas.intervalList.length; j++) {
            this.$set(datas.intervalList[j], "isShow", true);
            this.$set(datas.intervalList[j], "id", intId++);
            this.$set(datas.intervalList[j].posTrad, "isShow", true);
            for (let k = 0; k < datas.intervalList[j].productList.length; k++) {
              this.$set(datas.intervalList[j].productList[k], "isShow", true);
              this.$set(datas.intervalList[j].productList[k], "id", pid++);
            }
          }
          this.$nextTick(() => {
            this.data = JSON.parse(JSON.stringify(datas));
          });
        } else {
          this.$message({
            type: "error",
            message: res.data.message,
          });
        }
      });
    },
    /* 单通道政策模板 一键填入 */
    submitChildCover(data) {
      if (data.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率",
        });
      } else if (data.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入结算比例",
        });
      } else if (data.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入最低金额",
        });
      } else {
        for (let i = 0; i < data.intervalList.length; i++) {
          data.intervalList[i].posTrad.aptScale = data.aptScale;
          data.intervalList[i].posTrad.aptMin = data.aptMin;
          for (let p = 0; p < data.intervalList[i].productList.length; p++) {
            if (data.intervalList[i].productList[p].isSingleInterval == 0) {
              for (
                let s = 0;
                s <
                data.intervalList[i].productList[p].singlePayInterval.length;
                s++
              ) {
                data.intervalList[i].productList[p].singlePayInterval[
                  s
                ].aptRate = data.aptRate;
                data.intervalList[i].productList[p].singlePayInterval[
                  s
                ].aptScale = data.aptScale;
                data.intervalList[i].productList[p].singlePayInterval[
                  s
                ].aptMin = data.aptMin;
              }
            } else if (data.intervalList[i].productList[p].isSingleInterval == 1) {
              for ( let s = 0; s < data.intervalList[i].productList[p].singlePayInterval.length; s++ ) {
                data.intervalList[i].productList[p].singlePayInterval[s].aptRate = data.aptRate;
                data.intervalList[i].productList[p].singlePayInterval[s].creditAptRate = data.aptRate;
                data.intervalList[i].productList[p].singlePayInterval[s].aptScale = data.aptScale;
                data.intervalList[i].productList[p].singlePayInterval[s].creditAptScale = data.aptScale;
                data.intervalList[i].productList[p].singlePayInterval[s].aptMin = data.aptMin;
                data.intervalList[i].productList[p].singlePayInterval[s].creditAptMin = data.aptMin;
              }
            }
          }
        }
      }
    },
    /* 新增阶梯 */
    ladderAppend(interData) {
      let intData = JSON.parse(JSON.stringify(interData));
      intData.id = intId++;
      intData.aptStartMoney = intData.aptEndMoney;
      intData.aptEndMoney = intData.aptEndMoney + 1;
      intData.codeAdvanceRate = 0; //初始化 扫码垫资费费率
      intData.codeAdvanceMin = 0; //初始化 扫码垫资费费率最低值

      // 刷卡 赋空值
      Object.keys(intData.posTrad).forEach(key=>{
        if (key !== 'isShow') {
          intData.posTrad[key] = 0;
        }
      })

      // 扫码 赋空值
      for (let j = 0; j < interData.productList.length; j++) {
        intData.productList[j].id = pid++;
        for (
          let k = 0;
          k < interData.productList[j].singlePayInterval.length;
          k++
        ) {
          intData.productList[j].singlePayInterval[k].aptMin = 0;
          intData.productList[j].singlePayInterval[k].aptRate = 0;
          intData.productList[j].singlePayInterval[k].aptScale = 0;
          intData.productList[j].singlePayInterval[k].creditAptMin = 0;
          intData.productList[j].singlePayInterval[k].creditAptRate = 0;
          intData.productList[j].singlePayInterval[k].creditAptScale = 0;
        }
      }
      this.data.intervalList.push(intData);
    },
    /* 删除阶梯 */
    ladderRemove(interIndex) {
      this.data.intervalList.splice(interIndex, 1);
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/.el-tree-node__content {
  height: 40px;
  line-height: 40px;
  // background: #eeeeee;
  // border: 1px solid #eeeeee;
}

.aisle-policy-box {
  border: 1px solid #e0eafc;
  box-shadow: 0 2px 12px rgba(224, 234, 252, 0.8);
}
.aisle-policy-bg {
  background-color: #e0eafc;
  padding: 10px 0;
}
.policy-mr-3 {
  margin-right: 3px;
}
.policy-ml-3 {
  margin-left: 3px;
}
</style>